package com.eat.fish_service.controller.wx;


import com.eat.common_utils.R;
import com.eat.fish_service.entity.FishQuery;
import com.eat.fish_service.service.FishEncyclopediaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController("wxFishBaiKeController")
@CrossOrigin
@RequestMapping("/wx/fishbaike")
@Slf4j
@Api(tags = "微信鱼类百科")
public class FishBaiKeController {

    @Autowired
    private FishEncyclopediaService fishEncyclopediaService;


    @ApiOperation(value = "小程序端上传鱼的图片，返回图片路径，添加鱼百科的时候调用")
    @PostMapping("addFishBaiKePic")
    public R uploadFishPic(MultipartFile pic){
        return fishEncyclopediaService.addFishBaiKePic(pic);
    }

    @ApiOperation(value = "小程序端将鱼的类名，鱼的介绍，鱼的路径，文章作者存入数据库")
    @PostMapping("addFishBaiKe")
    public R addFishBaiKe(@RequestParam @ApiParam(name = "fishName", value = "鱼的类名", required = false) String fishName,
                          @RequestParam @ApiParam(name = "introduction", value = "鱼的介绍", required = false) String introduction,
                          @RequestParam @ApiParam(name = "fishImg", value = "鱼的图片路径", required = false) String fishImg,
                          @RequestParam @ApiParam(name = "author", value = "文章作者", required = false) String author){

        return fishEncyclopediaService.addFishBaiKe(fishName, introduction, fishImg, author);
    }

    //条件查询鱼百科带分页文件数据
    @ApiOperation(value = "小程序条件查询带分页文件数据")
    @PostMapping("getFishBaiKe/{current}/{size}")
    public R pageFishBaiKeCondition(@PathVariable
                               @ApiParam(name = "current", value = "当前页", required = true) Long current,
                                    @PathVariable
                               @ApiParam(name = "size", value = "每页显示条数", required = true)  Long size,
                                    @RequestBody(required = false)
                               @ApiParam(name = "fishQuery", value = "查询对象条件，鱼的介绍模糊查询，鱼类名和作者等值查询，时间范围查询", required = false) FishQuery fishQuery) {
      return fishEncyclopediaService.pageFishBaiKeCondition(current, size, fishQuery);
    }

    //根据id查询鱼百科数据
    @ApiOperation(value = "根据id查询鱼百科数据")
    @GetMapping("getFishBaiKe/{fishId}")
    public R getFishDiseaseCondition(@PathVariable @ApiParam(name = "fishId", value = "鱼Id", required = true) String fishId){
        return fishEncyclopediaService.getFishBaiKe(fishId);

    }

}
